//
//  AppDelegate.m
//  TinyFortune
//
//  Created by lc on 16/5/15.
//  Copyright © 2016年 lc. All rights reserved.
//

#import "AppDelegate.h"
#import "UMSocial.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // Enable Crash Reporting
    //[AVOSCloudCrashReporting enable];
    //设置AppKey
    [UMSocialData setAppKey:UMSocialAppKey];
    
    //===================云服务存储方面=======================
    [AVOSCloudCrashReporting enable];
    // Setup AVOSCloud
    [AVOSCloud setApplicationId:@"HM2kiJFj0F8NafOdAPn4rD1I-gzGzoHsz" clientKey:@"1NYRIF9GhcVP0vgCshj8ELVK"];
    // [AVOSCloud setAllLogsEnabled:YES];
    //===============推送方面=========================
    //请求用户权限
    //ios8 之后
//    if ([UIApplication instanceMethodForSelector:@selector(application:registerUserNotificationSettings:)]) {
//        
//        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
//        }
//    
//    //创建本地推送通知
//    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//      //设置标题
//    localNotification.alertTitle = @"小幸运";
//    //设置内容
//    localNotification.alertBody = @"主人思密达,你有新消息哦,快来看一看吧.";
//    //设置通知启动时间
//    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//    //设置通知的声音,声音资源必须在工程中,音频播放时间长度小于30秒
//    localNotification.soundName = @"音效.caf";
//    //将本地通知添加到系统队列中
//    [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
//    //设置应用程序角标
//    localNotification.applicationIconBadgeNumber = 100 ;
//
//    
//    //取消本地推送停止
//    //方式一:取消单个本地通知
//    //[[UIApplication sharedApplication]cancelLocalNotification:localNotification];
//    //方式二:取消全部本地通知
//    //[[UIApplication sharedApplication]cancelAllLocalNotifications];
    
    
    //请求用户权限,注册远程推送通知
//    if ([[UIDevice currentDevice].systemVersion floatValue] < 8.0) {
//        UIRemoteNotificationType types = UIRemoteNotificationTypeBadge |
//        UIRemoteNotificationTypeAlert |
//        UIRemoteNotificationTypeSound;
//        [application registerForRemoteNotificationTypes:types];
//    } else {
//        UIUserNotificationType types = UIUserNotificationTypeAlert |
//        UIUserNotificationTypeBadge |
//        UIUserNotificationTypeSound;
//        
//        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
//        
//        [application registerUserNotificationSettings:settings];
//        [application registerForRemoteNotifications];
//    
//    }
    
    
  
    
    return YES;
}

//注册远程推送的回调
//成功的时候回返回一个
//- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
//     NSLog(@"deviceToken:%@",deviceToken);
//    
//    //保存本台机器的deviceToken后，就可以发送推送了
//    AVInstallation *currentInstallation = [AVInstallation currentInstallation];
//    [currentInstallation setDeviceTokenFromData:deviceToken];
//    [currentInstallation saveInBackground];
//}
//远程通知失败的回调
//- (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error{
//   // NSLog(@"%@",error);
//}
//接受远程推送通知的回调
//- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
//    NSLog(@"11111");
//    NSLog(@" %s userInfo = %@",__func__,userInfo);
//    //{"aps":{"alert":"123456"}}
//    //取出Alert字符串
////    NSString *alertStr = [userInfo valueForKeyPath:@"aps.alert"];
////    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"远程推送" message:alertStr delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil];
////    [alertView show];
//    NSLog(@"receive : %@",userInfo);
//    application.applicationIconBadgeNumber = 1 ;
//}
//- (void)application:(UIApplication *)application
//didReceiveRemoteNotification:(NSDictionary *)userInfo
//fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
//   
//    NSLog(@"111");
//}

/**注册用户或者通知授权成功的回调*/
//- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(nonnull UIUserNotificationSettings *)notificationSettings{
//    
//
//}
//接受本地推送通知
//情景1:当应用程序未启动或者程序切换到后台,需要手动点击推送通知,才会回调
//情景2:当程序处于前台时,该方法自动回调,没有Alert弹出框和播放音频.
//- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
//    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:notification.alertTitle message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
//    [alertView show];
//    //接到通知后角标清0
//    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
//}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
